import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { rules } from '@pkg/utils';
import { Api } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';


export const columns: BasicColumn[] = [
  {
    title: '广告图',
    dataIndex: 'advImg',
    width: 70,
    customRender: render.renderImage,
  },
  {
    title: '广告标题',
    dataIndex: 'advName',
    width: 150,
  },
  {
    title: '显示位置',
    dataIndex: 'advType',
    width: 120,
    customRender: render.renderDict,
  },
  {
    title: '发布状态',
    dataIndex: 'advStatus',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const advStatusArray = [
        { label: '未发布', value: 0 },
        { label: '已发布', value: 1 },
      ];
      const advStatus: any = advStatusArray.find((item) => item.value == record.advStatus);
      if (advStatus) {
        return advStatus.label;
      }
      return '';
    },
  },
  {
    title: '跳转方式',
    dataIndex: 'jumpType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const jumpTypeArray = [
        { label: '外部链接', value: 1 },
        { label: '文本跳转', value: 2 },
        { label: '内部跳转', value: 3 },
        { label: '不跳转', value: 4 },
      ];
      const jumpType: any = jumpTypeArray.find((item) => item.value == record.jumpType);
      if (jumpType) {
        return jumpType.label;
      }
      return '';
    },
  },
  {
    title: '所属应用',
    dataIndex: 'weChatName',
    width: 150,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 100,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'advName',
    label: '广告名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    label: '广告位置',
    field: 'advType',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '首页广告', value: 1 },
        { label: '商城广告', value: 2 },
        { label: '弹窗广告', value: 3 },
      ],
    },
  },
  {
    field: 'weChatId',
    label: '公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: Api.list,
      showSearch: true,
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '广告标题',
    field: 'advName',
    component: 'Input',
    required: true,
  },
  {
    label: '广告位置',
    field: 'advType',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '首页广告', value: 1 },
        { label: '商城广告', value: 2 },
        { label: '弹窗广告', value: 3 },
      ],
    },
  },
  {
    label: '跳转方式',
    field: 'jumpType',
    component: 'ApiRadioGroup',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '外部链接', value: 1 },
        { label: '文本跳转', value: 2 },
        { label: '内部跳转', value: 3 },
        { label: '不跳转', value: 4 },
      ],
    },
  },
  {
    label: '所属应用',
    field: 'weChatId',
    component: 'ApiSelect',
    componentProps: {
      api: Api.list,
      showSearch: true,
      labelField: 'weChatName',
      valueField: 'weChatId',
    },
  },
  {
    label: '商品',
    field: 'goodsId',
    component: 'ApiModalSelect',
    required: false,
    show: ({ values }) => {
      return values.jumpType == 3;
    },
    componentProps: {
      multiple: '',
      selectConfig: {
        api: '/goods/page',
        rowKey: 'goodsId',
        labelKey: 'goodsName',
        modalTitle: '商品选择',
        searchForm: [
         
          {
            label: '商品名称',
            field: 'goodsName',
            component: 'Input',
          },
        ],
        columns: [
          {
            title: '商品封面',
            dataIndex: 'coverImg',
            width: 80,
            customRender: render.renderImage,
          },
          {
            title: '商品名称',
            dataIndex: 'goodsName',
            width: 150,
          },
          {
            title: '商品价格',
            dataIndex: 'goodsPrice',
            width: 100,
          },
          {
            title: '会员价格',
            dataIndex: 'vipPrice',
            width: 100,
          },
          {
            title: '创建日期',
            dataIndex: 'createTime',
            width: 150,
          },
        ],
      },
    },
  },
  {
    label: '排序',
    field: 'sort',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '图片',
    field: 'advImg',
    component: 'ImageUpload',
    required: true,
  },
  {
    label: '跳转地址',
    field: 'content',
    component: 'InputTextArea',
    rules: rules.url(true),
    ifShow: ({ values }) => {
      return values.jumpType == '1';
    },
  },
  {
    label: '内容',
    field: 'content',
    component: 'TyEditor',
    ifShow: ({ values }) => {
      return values.jumpType != '1';
    },
  },
];
